package com.example.mobile2021606134chhnewdemo.NewsModule;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.mobile2021606134chhnewdemo.R;

import java.util.List;

/**
 * @ClassName: NewContentRViewAdapter$
 * @Description: 作用
 * @Author: letquit
 * @CreateDate: 28/6/2021$
 * @Version: 1.0
 */
public class  NewContentRViewAdapter extends RecyclerView.Adapter<NewContentRViewAdapter.ViewHolder>{
    List<News> list;
    Context context;
    public NewContentRViewAdapter(List<News> list, Context context) {
        this.list = list;
        this.context = context;
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_new_content, null);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        News news = list.get(position);
        Glide.with(context).load(news.getPic()).into(holder.imgNewContent);
        holder.tvNewContent.setText(news.getContent());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvNewContent;
        ImageView imgNewContent;
        ScrollView childScroll;
        @SuppressLint("ClickableViewAccessibility")
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            this.imgNewContent = itemView.findViewById(R.id.imgNewContent);
            this.tvNewContent = itemView.findViewById(R.id.tvNewContent);
            this.childScroll = itemView.findViewById(R.id.childScroll);
            childScroll.setOnTouchListener(new View.OnTouchListener() {
                public boolean onTouch(View v, MotionEvent event) {
                    v.getParent().requestDisallowInterceptTouchEvent(true);
                    return false;
                }
            });
        }
    }
}
